<template>
  <div class="merchant-settlement-bill-detail views-container">
    <div class="wlm-table">
      <div
        class="wlm-table-header"
        style="margin-bottom:20px;"
      >
        <div class="dashboard-header">
          <el-row :gutter="8">
            <el-col :span="6">
              <div class="dashboard-header-item flex-col flex-justify-c flex-align-c">
                <div class="item-title"><span>入账数量</span>
                  <el-popover
                    placement="top-start"
                    trigger="hover"
                  >
                    <div style="font-size:12px">商家实际卖出的商品数</div>
                    <el-button
                      style="color:#333333"
                      type="text"
                      slot="reference"
                    >
                      <svg-icon
                        icon-class="wenhao"
                        style="font-size:20px"
                      />
                    </el-button>
                  </el-popover>
                </div>
                <div class="item-num">
                  <span>{{categoryData.sum_number||'0'}}</span>
                </div>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="dashboard-header-item flex-col flex-justify-c flex-align-c">
                <div class="item-title"><span>入账金额</span>
                  <el-popover
                    placement="top-start"
                    trigger="hover"
                  >
                    <div style="font-size:12px">商家实际得到的钱（除去分销佣金）</div>
                    <el-button
                      style="color:#333333"
                      type="text"
                      slot="reference"
                    >
                      <svg-icon
                        icon-class="wenhao"
                        style="font-size:20px"
                      />
                    </el-button>
                  </el-popover>
                </div>
                <div class="item-num">
                  <span><span class="orders-red">￥</span>{{categoryData.sum_money||'0'}}</span>
                </div>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="dashboard-header-item flex-col flex-justify-c flex-align-c ">
                <div class="item-title"><span>分销数量</span>
                  <el-popover
                    placement="top-start"
                    trigger="hover"
                  >
                    <div style="font-size:12px">实际已经结算佣金的商品数</div>
                    <el-button
                      style="color:#333333"
                      type="text"
                      slot="reference"
                    >
                      <svg-icon
                        icon-class="wenhao"
                        style="font-size:20px"
                      />
                    </el-button>
                  </el-popover>
                </div>
                <div class="item-num">
                  <span>{{categoryData.total_dealer_number||'0'}}</span>
                </div>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="dashboard-header-item flex-col flex-justify-c flex-align-c ">
                <div class="item-title"><span>分销佣金</span>
                  <el-popover
                    placement="top-start"
                    trigger="hover"
                  >
                    <div style="font-size:12px">实际已经结算的佣金</div>
                    <el-button
                      style="color:#333333"
                      type="text"
                      slot="reference"
                    >
                      <svg-icon
                        icon-class="wenhao"
                        style="font-size:20px"
                      />
                    </el-button>
                  </el-popover>
                </div>
                <div class="item-num">
                  <span><span class="orders-red">￥</span>{{categoryData.sum_commission||'0'}}</span>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
      <div class="wlm-table-content">
        <div class="wlm-table-header">
          <el-form
            :model="tableFormatData.userTable.files"
            size="small"
            class="retail-form"
            label-position="right"
          >
            <el-form-item
              label="门店选择："
              class="search"
            >
              <el-select
                v-model="tableFormatData.userTable.files.store_id"
                placeholder="请选择"
                style="width:250px;"
              >
                <el-option
                  v-for="item in storeData"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <!-- <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.name" placeholder="请输入商家名称" style="width:160px;"></el-input> -->
            </el-form-item>
            <el-form-item
              label=""
              class="filter-btns"
            >
              <el-button
                type="primary"
                @click="filesSerch"
                style="margin-right:20px;"
              >筛选</el-button>
              <el-button
                type="text"
                @click="filesEmpty"
              >清空筛选条件</el-button>
            </el-form-item>
          </el-form>
        </div>
        <el-tabs
          v-model="tableFormatData.userTable.files.get_status"
          type="card"
          @tab-click="filesSerch"
        >
          <!-- @tab-click="filesSerch" -->
          <!-- <el-tab-pane label="入账商品" name="1"></el-tab-pane> -->
          <el-tab-pane
            label="入账明细"
            name="2"
          ></el-tab-pane>
        </el-tabs>
        <!-- <p style="font-weight: 600;padding-bottom: 14px;">入账商品</p> -->
        <el-table
          v-if="tableFormatData.userTable.files.get_status=='1'"
          :ref="tableFormatData.userTable.key"
          :data="tableFormatData.userTable.tableData"
          @selection-change="handleSelectionChange"
          style="width: 100%"
        >
          <!-- <el-table-column type="selection" width="55">
                </el-table-column> -->
          <el-table-column
            prop="name"
            label="编号"
            min-width="40"
          >
            <template slot-scope="scope">
              <span>{{scope.row.sum_number}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="date"
            label="商品"
          >
            <template slot-scope="scope">
              <div class="wlm-table-logos flex-row">
                <img
                  class="logo"
                  :src="scope.row.image.file_path"
                >
                <el-popover
                  placement="top-start"
                  width="200"
                  trigger="hover"
                  :content="scope.row.goods_name"
                >
                  <p
                    slot="reference"
                    style="line-height:32px;width:200px;"
                    class="ellipsis"
                  >{{ scope.row.goods_name }}</p>
                </el-popover>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="数量"
          >
            <template slot-scope="scope">
              <span>{{scope.row.sum_number}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="小计"
          >
            <template slot-scope="scope">
              <span>{{scope.row.sum_pay_price ||'-'}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="入账金额"
          >
            <template slot-scope="scope">
              <span>{{scope.row.sum_money}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="分销金额"
          >
            <template slot-scope="scope">
              <span>{{scope.row.sum_commission ||'-'}}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="wlm-table-content">
        <!-- <p style="font-weight: 600;padding:30px 0 14px 0;">入账明细</p> -->
        <el-table
          v-if="tableFormatData.userTable.files.get_status=='2'"
          :ref="tableFormatData.userTable.key"
          :data="tableFormatData.userTable.tableData"
          @selection-change="handleSelectionChange"
          style="width: 100%"
        >
          <el-table-column
            prop="date"
            label="订单号/消费方式"
            min-width="55"
          >
            <template slot-scope="scope">
              <p>{{scope.row.order_no}}</p>
              <p v-if="scope.row.express_type=='1'">快递</p>
              <p v-if="scope.row.express_type=='2'">自提</p>
              <p v-if="scope.row.express_type=='3'">核销</p>
              <p v-if="scope.row.express_type=='4'">卡密</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="商品名称"
          >
            <template slot-scope="scope">
              <div class="wlm-table-logos flex-row">
                <img
                  class="logo"
                  v-if="scope.row.image"
                  :src="scope.row.image.file_path"
                >
                <el-popover
                  placement="top-start"
                  width="180"
                  trigger="hover"
                  :content="scope.row.goods_name"
                >
                  <p
                    slot="reference"
                    style="line-height:32px;width:160px;margin-left: 6px;"
                    class="ellipsis"
                  >{{ scope.row.goods_name }}</p>
                </el-popover>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="用户信息"
            min-width="45"
          >
            <template slot-scope="scope">
              <p>{{scope.row.nickName}}</p>
              <p>{{scope.row.mobile}}</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="归属门店"
            min-width="45"
          >
            <template slot-scope="scope">
              <span>{{scope.row.store_name ||'-'}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="结算比例类型"
            min-width="45"
          >
            <template slot-scope="scope">
              <span>{{scope.row.settlement_type ||'-'}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="结算比例*数量"
            min-width="40"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.settlement_rate">
                <!-- <template v-if="scope.row.settlement_type_num == 1">￥</template> -->
                <template>{{scope.row.settlement_rate}}*{{scope.row.number}}</template>
                <!-- <template v-if="scope.row.settlement_type_num != 1">%</template> -->
              </span>
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="商家入账"
            min-width="35"
          >
            <template slot-scope="scope">
              <span>￥{{scope.row.get_money}}</span>
              <el-tag
                v-if="scope.row.settlement_status==1"
                type="info"
              >未结算</el-tag>
              <el-tag
                v-if="scope.row.settlement_status==2"
                type="success"
              >已结算</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="核销人员"
            min-width="35"
          >
            <template slot-scope="scope">
              <span>{{scope.row.clerk_name||'-'}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="分销数据"
            min-width="35"
          >
            <template slot-scope="scope">
              <span>{{scope.row.dealer_money||'-'}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="平台销售"
            min-width="35"
          >
            <template slot-scope="scope">
              <span>￥{{scope.row.money}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="入账时间"
            min-width="52"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.create_time }}</span>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-content flex-row flex-justify-e flex-align-c">
          <!-- <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" type="primary" :disabled="isGroup" size="mini" @click="auditBatch({redirect:'ids',id:'all',toggle:'dialogTableVisible',noEdit:true})">批量审核</el-button>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
                </el-row> -->
          <el-pagination
            :disabled="!hasTableData"
            @size-change="listPageChange"
            @current-change="listPageChange"
            :current-page.sync="tableFormatData.userTable.pagination.page"
            :page-sizes="tableFormatData.userTable.pagination.pagesizes"
            :page-size.sync="tableFormatData.userTable.pagination.list_rows"
            layout="total, sizes, prev, pager, next, jumper"
            :total="hasTableData?tableFormatData.userTable.pagination.total : 0"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getBillDetail,
  shopIndex
} from '@/api/merchant'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'MerchantSettlementBillDetail',
  components: {
  },
  created() {
    // this.$nextTick(() => {

    // })
    this.newdata()

  },
  data() {
    return {
      storeData: [{
        id: -1,
        name: '管理员核销',
        checked: true,
      }],
      value: '',
      categoryData: {},
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: getBillDetail
          },
          tableData: [],
          files: {
            store_id: '',
            get_status: '2',
            ids: [],
            checkall: '0',
            Recycle: '1'
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  created() {
    this.$nextTick(()=>{
    this.newdata()

    })
  },
//   mounted () {
//       this.newdata()
//   },
  methods: {
    changbtn() {
      shopIndex({ bus_id: this.$route.query.id, is_page: '2' }).then(res => {
        this.storeData.push(...res.data.data);
        //   this.storeData = res.data.data
        console.log("4111111111111111111", this.storeData)
      })
    },
    newdata() {
      getBillDetail({ year: this.$route.query.year, month: this.$route.query.month, day: this.$route.query.day, type: this.$route.query.type, get_status: 3, id: this.$route.query.id }).then((response) => {
        const {
          data: {
            data: msgData = []
          }
        } = response
        console.log("22222")
        this.categoryData = msgData
      })
    }
  }
}
</script>
